package com.carcenter.order.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carcenter.common.model.dto.ServiceQueryDto;
import com.carcenter.common.page.MyPageData;
import com.carcenter.common.result.Result;
import com.carcenter.order.entity.Services;
import com.carcenter.order.service.IServicesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@RestController
@RequestMapping("/services")
public class ServicesController {
    @Autowired
    private IServicesService service;
    @PostMapping("/getServiceList/{pageNum}/{pageSize}")
    public Result getServices(@PathVariable Integer pageNum,
                              @PathVariable Integer pageSize,
                              @RequestBody ServiceQueryDto serviceQueryDto
                              ){
        IPage<Services> page = service.getServices(pageNum,pageSize,serviceQueryDto);
        MyPageData data = new MyPageData(page.getTotal(),page.getRecords());
        return Result.ok(data);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Services services){
        service.saveOrUpdate(services);
        return Result.ok();
    }

    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable Integer id){
        service.removeById(id);
        return Result.ok();
    }
    @PutMapping("/release/{id}")
    public Result release(@PathVariable Integer id){
        LambdaUpdateWrapper<Services> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Services::getStatus,1).eq(Services::getId,id);
        service.update(updateWrapper);
        return Result.ok();
    }
    @GetMapping("/getService/{id}")
    public Result getService(@PathVariable Integer id){
        Services services = service.getById(id);
        return Result.ok(services);
    }

}
